//
//  工程名称:XJL_WeChat
//  文件名称:XJLChangeAccountViewController.m
//
//  创建者  :Created by 许佳莉
//  创建时间:on 16/7/31.
//  版权   :  Copyright © 2016年 Xujiali. All rights reserved.
//

#import "XJLChangeAccountViewController.h"

@interface XJLChangeAccountViewController()
@property (weak, nonatomic) IBOutlet UITextField *loginAccountField;
@property (weak, nonatomic) IBOutlet UITextField *loginPwdField;


@end
@implementation XJLChangeAccountViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    
    [self.loginAccountField becomeFirstResponder];
}
- (IBAction)login:(UIButton *)sender {
    [self.view endEditing:YES];
    
    [SVProgressHUD showWithStatus:@"登录中..."];
    
    [[EaseMob sharedInstance].chatManager asyncLoginWithUsername:self.loginAccountField.text password:self.loginPwdField.text completion:^(NSDictionary *loginInfo, EMError *error) {
        if (!error && loginInfo) {
            XJLLog(@"登录成功");
            
            //把登录账号保存到沙盒
            [NSUserDefaults saveLastLoginAcount:self.loginAccountField.text];
            
            //进入主界面
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            self.view.window.rootViewController = sb.instantiateInitialViewController;
        }else{
            //登录失败
            [SVProgressHUD showErrorWithStatus:error.description];
        }
    } onQueue:nil];
}

- (IBAction)back {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
